#include "Energy.h"


Energy::Energy(void) {
	shieldEnergy = 0;
	maxEnergy = 300;
	remEnergy = maxEnergy;
	hitEnergy = 0;
	phaserEnergy = 0;
}


Energy::~Energy(void) {

}

Energy::Energy(int mEnergy) {
	maxEnergy = mEnergy;
	shieldEnergy = 0;
	remEnergy = maxEnergy;
	hitEnergy = 0;
	phaserEnergy = 0;
}


void Energy::shieldUsed(int sEnergy) {
	// negative sEnergy reduces amount of energy is placed on the shield
	if(sEnergy >= 0) {
		if(shieldEnergy + sEnergy > MAXSHIELD) {
			remEnergy -= (MAXSHIELD - shieldEnergy);
			shieldEnergy = MAXSHIELD;
		}
		else {
			shieldEnergy += sEnergy; 
			remEnergy -= sEnergy;
		}
	}
	if(sEnergy < 0) {
		if(shieldEnergy - sEnergy < 0) {
			remEnergy += shieldEnergy;
			shieldEnergy = 0;
		}
		else {
			shieldEnergy -= sEnergy;
			remEnergy += sEnergy;
		}
	}
}

void Energy::phaserUsed(int pEnergy) {
	remEnergy -= pEnergy;
	phaserEnergy = pEnergy;
}

void Energy::shieldDmg(Energy *other, gObject *tObj,gObject *oObj) {
	V3DF delta;
	delta =  tObj->getCen() - oObj->getCen();
	hitEnergy = (int)(other->phaserEnergy /(( rand() % 3 + 2) + sqrt((delta.x * delta.x) + (delta.y *delta.y))));
	shieldEnergy -= hitEnergy;
}

void Energy::torpedoUsed(int num) {
	remEnergy -= (2 * num);
}

void Energy::LRSUsed() {
	remEnergy -= LRS_ENERGY;
}

void Energy::boostUsed() {
	remEnergy -= BOOST_ENERGY;
}

void Energy::moveUsed(float dt) {
	static float temp;
	temp = 0;
	temp += dt;
	if((int)temp % 5 == 0) {
		remEnergy -= 2;
		temp = 0;
	}
}

void Energy::setMaxEnergy(int m) {
	maxEnergy = m;
}

void Energy::setRemEnergy(int r) {
	remEnergy = r;
}
void Energy::setShieldEnergy(int s) {
	shieldEnergy = s;
}
void Energy::setPhaserEnergy(int p) {
	phaserEnergy = p;
}